//package com.alice.util;
//
//import com.alibaba.fastjson.JSONObject;
//import com.github.dockerjava.api.DockerClient;
//import com.github.dockerjava.api.command.CreateContainerResponse;
//import com.github.dockerjava.api.model.ExposedPort;
//import com.github.dockerjava.api.model.Info;
//import com.github.dockerjava.api.model.Ports;
//import com.github.dockerjava.core.DefaultDockerClientConfig;
//import com.github.dockerjava.core.DockerClientConfig;
//
//public class DockerClientService {
//    /**
//     * 连接docker服务器
//     * @return
//     */
//    public DockerClient connectDocker(){
//        DockerClientConfig custom = DefaultDockerClientConfig.createDefaultConfigBuilder()
//                .withDockerHost("tcp://docker.somewhere.tld:2376")
//                .withDockerTlsVerify(true)
//                .withDockerCertPath("/home/user/.docker")
//                .withRegistryUsername("")
//                .withRegistryPassword("")
//                .withRegistryEmail("")
//                .withRegistryUrl("")
//                .build();
//
//        return custom;
//    }
//
//    /**
//     * 创建容器
//     * @param client
//     * @return
//     */
//    public CreateContainerResponse createContainers(DockerClient client, String containerName, String imageName){
//        //映射端口8088—>80
//        ExposedPort tcp80 = ExposedPort.tcp(80);
//        Ports portBindings = new Ports();
//        portBindings.bind(tcp80, Ports.Binding.bindPort(8088));
//
//        CreateContainerResponse container = client.createContainerCmd(imageName)
//                .withName(containerName)
//                .withHostConfig(newHostConfig().withPortBindings(portBindings))
//                .withExposedPorts(tcp80).exec();
//        return container;
//    }
//
//
//    /**
//     * 启动容器
//     * @param client
//     * @param containerId
//     */
//    public void startContainer(DockerClient client,String containerId){
//        client.startContainerCmd(containerId).exec();
//    }
//
//    /**
//     * 启动容器
//     * @param client
//     * @param containerId
//     */
//    public void stopContainer(DockerClient client,String containerId){
//        client.stopContainerCmd(containerId).exec();
//    }
//
//    /**
//     * 删除容器
//     * @param client
//     * @param containerId
//     */
//    public void removeContainer(DockerClient client,String containerId){
//        client.removeContainerCmd(containerId).exec();
//    }
//}
